//
//  TapViewController.m
//  UITest
//
//  Created by wp w on 12-6-12.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "TapViewController.h"
@implementation TapViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    //很多时候鼠标、手势不起作用，此时：
    //view明确表示已经使用了
    //此时鼠标、手势等，会起作用
    self.view.backgroundColor = [UIColor grayColor];
    
    //单手指，单击
    UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    singleTapOne.numberOfTouchesRequired = 1; //单击
    singleTapOne.numberOfTapsRequired = 1; //单手指
    singleTapOne.delegate = self;
    
    //单手指，双击
    UITapGestureRecognizer *singleTapTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    singleTapTwo.numberOfTouchesRequired = 2; 
    singleTapTwo.numberOfTapsRequired = 1; 
    singleTapTwo.delegate = self;
    
    //双手指，单击
    UITapGestureRecognizer *doubleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    doubleTapOne.numberOfTouchesRequired = 1; 
    doubleTapOne.numberOfTapsRequired = 2; 
    doubleTapOne.delegate = self;
    
    //双手指，双击
    UITapGestureRecognizer *doubleTapTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    doubleTapTwo.numberOfTouchesRequired = 2; 
    doubleTapTwo.numberOfTapsRequired = 2; 
    doubleTapTwo.delegate = self;
    
    // Single tap requires double tap to fail
    [singleTapOne requireGestureRecognizerToFail:doubleTapOne]; 
    [singleTapTwo requireGestureRecognizerToFail:doubleTapTwo];
    
    //为view注册这个手势识别对象
    [self.view addGestureRecognizer:singleTapOne]; 
    [singleTapOne release];
    [self.view addGestureRecognizer:singleTapTwo]; 
    [singleTapTwo release];
    [self.view addGestureRecognizer:doubleTapOne]; 
    [doubleTapOne release];
    [self.view addGestureRecognizer:doubleTapTwo]; 
    [doubleTapTwo release];
}

- (void)handleSingleTap:(UITapGestureRecognizer *)sender {
    if (sender.numberOfTouchesRequired == 1) {
        NSLog(@"Single Tap with a finger.");
    }
    else if (sender.numberOfTouchesRequired == 2) {
        NSLog(@"Single Tap with two finger.");
    }
}
- (void)handleDoubleTap:(UITapGestureRecognizer *)sender {
    if (sender.numberOfTouchesRequired == 1) {
        NSLog(@"Double Tap with a finger.");
    }
    else if (sender.numberOfTouchesRequired == 2) {
        NSLog(@"Double Tap with two finger.");
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesBegan");
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
//    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



@end
